﻿<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Exam.aspx.cs" Inherits="Student_Exam" EnableViewState="false" EnableSessionState="False" EnableEventValidation="false" ValidateRequest="false" %>
<%--<%@ OutputCache Duration="3600" Location="Client" VaryByCustom="browser" VaryByParam="*" %>--%>

<!doctype html>
<html>
<head runat="server">
<meta http-equiv="x-ua-compatible" content="ie=7" />
<link href="../css/Exam.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="../js/jquery/jquery-1.4.4.min.js"></script>
<script type="text/javascript" src="../js/jquery/jquery.cookie.js"></script>
<script type="text/javascript" src="../js/shielding.js"></script>
<script type="text/javascript">
var isAnswer = [];//保存已经回答的
$(function() {
    setcontent();
    showTime();
    $(".btn").mouseover(function() { $(this).css("background-position", "-90px "); }).mouseout(function() { $(this).css("background-position", "0px 0px"); });
});
window.onresize = function () { setcontent(); };
//设置页面布局
function setcontent(){
    var obj = $("#content");
    var windowWidth = document.documentElement.clientWidth;
    var windowHeight = document.documentElement.clientHeight;
    $(obj).css({
        "width": windowWidth - 200,
        "height": windowHeight - 70 - 64,
        "float": "left"
    });
}

//时间倒计时脚本
function showTime() {
    var timeLeft = <%=model.PaperTime%>;         //剩余时间，以分钟记
    var i = 0;                 //计数器，计算setTimeout需要的延迟时间
    updateTime(timeLeft);    //先更新一下时间表
    while (timeLeft > 0) {
        timeLeft--;//$.cookie("name", "value"+,{expires: 7});
        $.cookie('timeLeft', timeLeft);
        i++;
        //每一分钟1000*60*i时间减一，同时更新显示时间
        setTimeout("updateTime(" + timeLeft + ")", 1000 * 60 * i);
    }
    //循环完毕提交表单
    setTimeout("Submite()", 1000 * 60 * i);
}
function updateTime(timeLeft) {
    var t = $.cookie('timeLeft');
    if(t==null || t==0  || t=="0")
        t = timeLeft;
    document.getElementById("spantime").innerHTML = t;
}

function Sel(id) {
    var obj = $("#question_" + id);
    //alert(obj.css("background-color"));
    var bgcolor = obj.css("background-color");
    if (bgcolor.toLowerCase() != "#d3ffd3") {//说明第一次点击
        obj.css({ "background-color": "#d3ffd3" });
        isAnswer.push(id);
        $("#status").html(isAnswer.length);
    }
}
function SubmiteExam(){
    if(confirm("你确定要交卷么？")){
        Submite();
    }
}

//document.onkeydown = KeyDown;//屏蔽鼠标 F5等
</script>
    <title><%=model.PaperName %></title>
</head>
<body>
<form id="form1" runat="server">
<div class="page">

    <div class="banner">
        <div style="float:left;margin-top:15px;color:#FFF;"><h1><%=model.PaperName %></h1></div>
        <div class="banner_right"></div>
    </div>

    <div class="main">
    
    <div id="content">

    <% 
        for (int i = 0; i < model.ExamQuestionTypeList.Count; i++) {
           %>
    <div class="questionTypeTitle">
        <div>
        第<%=i+1 %>大题、
        <%=model.ExamQuestionTypeList[i].QuestionTypeTitle.Trim()%>
        每题<%=model.ExamQuestionTypeList[i].Score %>分 
        共计<%=model.ExamQuestionTypeList[i].QuestionList.Count%>道题
        </div>
    </div>
    <div  class="questionlist">
        <%
            System.Collections.Generic.List<Exam.Core.Model.ExamQuestion> objQuestions = model.ExamQuestionTypeList[i].QuestionList;
            for (int k = 0; k < objQuestions.Count; k++) {
                System.Collections.Generic.List<Exam.Core.Model.ExamQuestion> questionlist = new System.Collections.Generic.List<Exam.Core.Model.ExamQuestion>();

                //改变题目排列顺序
                Exam.AppClass.PaperType type = Exam.AppClass.PaperType.Outoforder;
                if (int.Parse(model.PaperType.Trim()) == (int)type) {
                    //objQuestions 乱序
                    
                    questionlist = Tools.GetRandomList(objQuestions);
                }
                else {
                    questionlist = objQuestions;
                }
                %>
            <div class="question" id="question_<%=questionlist[k].QuestionId.Trim()%>">
                <div class="questioncontent">
                <span style="margin-top:10px;color:#005500;">第<%=getNumber(k+1) %>小题、<!--<%=questionlist[k].QuestionId.Trim()%>--></span> 
                <%=Server.HtmlDecode(questionlist[k].QuestionContent.Trim())%></div>
                
                <div class="questionanswer">
                    <%if (model.ExamQuestionTypeList[i].QuestionTypeAttr.Trim() == "0") {%>
                    
                    <%if (questionlist[k].QuestionType.Trim()=="1") {%><!--单选-->
                        <div class="optsContent">
                        <%System.Collections.Generic.List<Exam.Core.Model.ExamOpts> objOpts = questionlist[k].ExamOptsList;
                        for (int m = 0; m < objOpts.Count; m++) { %>
                            <!--题型_试题ID-->
                            <input id="Rad_<%=objOpts[m].QuestionId.Trim() %>_<%=objOpts[m].QuestionOptsID %>" name="1_<%=objOpts[m].QuestionId.Trim() %>" type="radio" value="<%=objOpts[m].QuestionOptsValue.Trim()%>" onclick="return Sel('<%=objOpts[m].QuestionId.Trim() %>')" />
                            <label for="Rad_<%=objOpts[m].QuestionId.Trim() %>_<%=objOpts[m].QuestionOptsID %>">
                            <%=objOpts[m].QuestionOptsValue.Trim()%> <%=Server.HtmlDecode(objOpts[m].QuestionOptsText.Trim())%>
                            </label>
                        <%} %>
                        </div>
                    <%} %>
                    <%else if (questionlist[k].QuestionType.Trim()=="2") {%><!--多选-->
                        <div class="optsContent">
                        <%System.Collections.Generic.List<Exam.Core.Model.ExamOpts> objOpts = questionlist[k].ExamOptsList;
                        for (int m = 0; m < objOpts.Count; m++) { %>
                            <input id="Rad_<%=objOpts[m].QuestionId.Trim() %>_<%=objOpts[m].QuestionOptsID %>" name="2_<%=objOpts[m].QuestionId.Trim() %>" type="checkbox" value="<%=objOpts[m].QuestionOptsValue.Trim()%>" onclick="return Sel('<%=objOpts[m].QuestionId.Trim() %>')" />
                            <label for="Rad_<%=objOpts[m].QuestionId.Trim() %>_<%=objOpts[m].QuestionOptsID %>">
                            <%=objOpts[m].QuestionOptsValue.Trim()%> <%=Server.HtmlDecode(objOpts[m].QuestionOptsText.Trim())%>
                            </label>
                        <%} %>
                        </div>
                    <%} %>
                    <%else if (questionlist[k].QuestionType.Trim()=="3") {%><!--判断-->
                            <input id="Rad_3_1_<%=questionlist[k].QuestionId.Trim() %>" name="3_<%=questionlist[k].QuestionId.Trim() %>" type="radio" value="true"  onclick="return Sel('<%=questionlist[k].QuestionId.Trim() %>')" />
                            <label for="Rad_3_1_<%=questionlist[k].QuestionId.Trim() %>">正确</label>
                            <input id="Rad_3_2_<%=questionlist[k].QuestionId.Trim() %>" name="3_<%=questionlist[k].QuestionId.Trim() %>" type="radio" value="false" onclick="return Sel('<%=questionlist[k].QuestionId.Trim() %>')" />
                            <label for="Rad_3_2_<%=questionlist[k].QuestionId.Trim() %>">错误</label>
                    <%} %>
                    
                        
                        
                    <%}
                      else { %>
                        <div class="answerContent"><textarea id="txt_<%=questionlist[k].QuestionType %>_<%=questionlist[k].QuestionId.Trim() %>" name="<%=questionlist[k].QuestionType %>_<%=questionlist[k].QuestionId.Trim() %>" style="width:410px;height:40px;"  onclick="return Sel('<%=questionlist[k].QuestionId.Trim() %>')" ></textarea></div>
                    <%} %>
                </div>
            </div>
        <%} %>
    </div>
    
    
    <%} %>
    </div>
    
    <div id="right">
        <img src="../images/Info.png" border=0 style="vertical-align:middle" />信息：<br />
        <div>答卷时间：<%=model.PaperTime%>分钟</div>
        <div>开始时间：</div>
        <div><%=DateTime.Now%></div>
        <div>倒计时：</div>
        <div id="countdown"></div>
        <div style="color:#FF0000;font-weight:bold;">
            剩余：<span id="spantime" ><%=model.PaperTime%></span>分钟</div>
        <div>共计<%=qnumber%>道题</div>
        <div>已答 <span id="status">0</span> 道题</div>
        <div>
            <input id="Button1" type="button" class="button" value="交卷" onclick="SubmiteExam()" /></div>
        <div id="subStatus"></div>
    </div>

    </div>

    <br class="clear" />
    <div id="footer">
    <input id="Button4" type="button" class="button" value="隐藏已答" onclick="hide()" />
    <input id="Button5" type="button" class="button" value="显示已答" onclick="show()" />
    </div>
</div>
</form>
<script>
function hide() {
    for (var i = 0; i < isAnswer.length; i++) {
        var obj = $("#question_" + isAnswer[i]).hide();
    }
    var div = $("#content");
    div.scrollTop = div.scrollHeight;
}
function show() {
    for (var i = 0; i < isAnswer.length; i++) {
        var obj = $("#question_" + isAnswer[i]).show();
    }
}

function Submite(){
    //获取试题ID和考生答案
    //表单
    var sbtype = "<%=sbtype.ToString().Trim('|') %>"; //题型
    var typelist = sbtype.split("|");
    var list = "<%=sb.ToString().Trim('|') %>"; //题型_题目编号
    var qlist = list.split("|");
    var frm = "{";
    frm += "\"paper\":[";
    for (var m = 0; m < qlist.length; m++) {//循环题型
        
        frm += "{";
        frm += "\"" + typelist[m] + "\":{";
        var frmList = qlist[m].split(",");
        for (var a = 0; a < frmList.length; a++) {//循环题型下试题
            var inputName = frmList[a];
            var inputValue = "";
            if (inputName.split("_")[0] == "1") {//单选按钮
                inputValue = $("input[name=" + inputName + "][checked]").val();
            } else if (inputName.split("_")[0] == "2") {//多选按钮
                inputValue = $("input[name=" + inputName + "][checked]").val();
            } else if (inputName.split("_")[0] == "3") {//判断按钮
                inputValue = $("input[name=" + inputName + "][checked]").val();
            }else {
                inputValue = $("input[name=" + inputName + "]").val();
            }
            if (inputValue == undefined) {//未选答案 设置为空字符串
                inputValue = "";
            }

            frm += '"' + inputName + '"' + ":" + '"' + inputValue + '"'+",";
        }
        frm = frm.substring(0, frm.length - 1);

        frm += "}},";
    }
    frm = frm.substring(0, frm.length - 1);

    frm += "],\"paperid\":\"<%=id %>\",";//试卷ID
    frm += "\"myid\":\"<%=isTheMe.StudentID %>\","; //考生ID
    frm += "\"paperfilepath\":\"<%=paperfilepath.Trim() %>\","; //考卷路径
    frm += "\"typelist\":\"<%=sbtype.ToString().Trim() %>\","; //题型列表
    frm += "\"SEId\":\"<%=SEId %>\""; //考生考卷表
    frm += "}";

    $.ajax({
        type: "POST",
        cache: false,
        url: "Service/exam.aspx",
        data: frm, //eval("(" + frm + ")"),
        //dataType: "json",
        //contentType: 'application/json; charset=utf8',
        beforeSend: function () {
            $("#subStatus").html("<img src='../images/ajax-loader.gif' border=0 /> 交卷中...");
        },
        success: function (msg) {
            if (msg == "1") {
                $("#subStatus").html("<img src='../images/ok.gif' border=0 /> 提交完成");
                //设置按钮为不可再次提交状态
                $("#Button1").attr("disabled", "disabled");
            } else {
                //alert("失败！请重新");
                $("#subStatus").html("<img src='../images/erro.gif' border=0 /> 提交失败，请重新提交");
            }
        },
        error: function (msg) {
            //alert("失败！请重新");
            $("#subStatus").html("<img src='../images/erro.gif' border=0 /> 发生错误，请重新提交");
        }
    });
}
</script>    
</body>
</html>
